import * as Cookies from "js-cookie";

export const USER_ID: string = "X-USER-ID";
export const USER_NAME: string = "X-USER-NAME";
export const CLIENT_TAG: string = "X-CLIENT-TAG";

export class Cache {
  public static getUserId(): string | undefined {
    return Cookies.get(USER_ID);
  }

  public static setUserId(userId: string): void {
    Cookies.set(USER_ID, userId);
  }

  public static removeUserId(): void {
    Cookies.remove(USER_ID);
  }

  public static getUserName(): string | undefined {
    return Cookies.get(USER_NAME);
  }

  public static setUserName(name: string): void {
    Cookies.set(USER_NAME, name);
  }

  public static removeUserName(): void {
    Cookies.remove(USER_NAME);
  }

  public static getClientTag(): number | undefined {
    if (Cookies.get(CLIENT_TAG) == undefined) {
      return undefined;
    } else {
      return parseInt(<string>Cookies.get(CLIENT_TAG));
    }
  }

  public static setClientTag(client_tag: number): void {
    Cookies.set(CLIENT_TAG, client_tag.toString())
  }

  public static removeClientTag(): void {
    Cookies.remove(CLIENT_TAG);
  }
}
